package com.ly.hotel.spainterface.jxd.utils;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.ly.hotel.webagent.UdpCallback;
import com.ly.hotel.webagent.UdpClient;

/**
 * Created by ThinkPad on 2018/3/20.
 */

public class UdpUtils{


    public void  getUdpResult(final String ip, final String port, final String req,
                              final Handler handler, final int requestCode){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    UdpCallback callback = new UdpCallback() {
                        @Override
                        public void receive(String s) {
                            Message message = new Message();
                            message.what = 1;
                            message.obj = s;
                            message.arg1 = requestCode;
                            handler.sendMessage(message);
                        }
                    };
                    int serverIP = Integer.parseInt(port);
                    new UdpClient(ip, serverIP, callback, "<gs", "</gs>", "Msg").send(req);
                } catch (NumberFormatException n) {
                    Log.i("JxdJSActivity", "转换出错");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
